package com.hsteach.web.controller.myopia;

import com.hsteach.common.annotation.Anonymous;
import com.hsteach.common.core.controller.BaseController;
import com.hsteach.common.core.domain.AjaxResult;
import com.hsteach.common.core.page.TableDataInfo;
import com.hsteach.common.utils.SecurityUtils;
import com.hsteach.dao.domain.myopia.Myopia;
import com.hsteach.dao.domain.myopia.MyopiaInfo;
import com.hsteach.service.myopia.MyopiaService;
import com.hsteach.web.controller.myopia.dto.MyopiaAddDTO;
import com.hsteach.web.controller.myopia.dto.MyopiaAreaListDTO;
import com.hsteach.web.controller.myopia.dto.MyopiaInportDto;
import com.hsteach.web.controller.myopia.dto.MyopiaListDTO;
import com.hsteach.web.controller.myopia.vo.MyopiaRiskVO;
import com.hsteach.web.dto.PageDto;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.util.List;

/**
 * 近视管理Controller
 * 
 * @author lx
 * @date 2023-07-07
 */
@Api(value = "近视管理", tags = "近视管理")
@RestController
@RequestMapping("/myopia")
public class MyopiaController extends BaseController
{
    @Autowired
    private MyopiaService myopiaService;

    /**
     * 查询学校近视管理列表
     */
    @ApiOperation("查询学校近视档案列表")
    @GetMapping("/list")
    public TableDataInfo list(@Validated MyopiaListDTO dto)
    {
        startPage();
        List<Myopia> list = myopiaService.selectList(dto);
        return getDataTable(list);
    }

    /**
     * 查询学校近视管理列表
     */
    @ApiOperation("区域查询学校近视档案列表")
    @GetMapping("/areaList")
    public TableDataInfo areaList(@Validated MyopiaListDTO dto)
    {
        List<Myopia> list = myopiaService.areaList(dto);
        return getDataTable(list);
    }

    /**
     * 根据学生id查询用户
     */
    @ApiOperation("根据身份证id和学籍号查询用户名")
    @GetMapping("/getStudent")
    public AjaxResult getStudent(String idCard,String stuCode)
    {
        return success(myopiaService.getStudent(idCard,stuCode));
    }

    /**
     * 根据档案id获取详情
     */
    @ApiOperation("查询学校近视档案详情")
    @GetMapping("/info")
    public TableDataInfo getInfo(Long id)
    {
        startPage();
        List<MyopiaInfo> list = myopiaService.getInfoList(id);
        return getDataTable(list);
    }

    /**
     * 新增视力档案
     */
    @ApiOperation("新增视力档案")
    @PostMapping()
    public AjaxResult add(@RequestBody MyopiaAddDTO dto)
    {
        myopiaService.add(dto);
        return success();
    }

    /**
     * 学校获取年级青少年占比
     * @param
     * @return
     * @throws Exception
     */
    @ApiOperation("已近视儿童青少年占比1")
    @GetMapping("/getSchoolProportion")
    public AjaxResult getSchoolProportion(String schoolId) throws Exception {
        return success(myopiaService.getSchoolProportion(SecurityUtils.getAuthInfo().getOrganizeId()));
    }

    /**
     * 区域获取阶段近视青少年占比
     * @param
     * @return
     * @throws Exception
     */
    @ApiOperation("区域获取阶段近视青少年占比")
    @GetMapping("/getProportion")
    public AjaxResult getProportion() throws Exception {
        return success(myopiaService.getProportion());
    }


    /**
     * 学校获取年级近视程度
     * @param
     * @return
     * @throws Exception
     */
    @ApiOperation("学校获取年级近视程度统计")
    @GetMapping("/getGradeLevelStat")
    public AjaxResult getGradeLevelStat(String schoolId) throws Exception {
        return success(myopiaService.getGradeLevelStat(SecurityUtils.getAuthInfo().getOrganizeId()));
    }

    /**
     * 区域获取阶段近视程度
     * @param
     * @return
     * @throws Exception
     */
    @ApiOperation("区域获取阶段近视程度")
    @GetMapping("/getStageLevelStat")
    public AjaxResult getStageLevelStat() throws Exception {
        return success(myopiaService.getStageLevelStat());
    }


    /**
     * 已近视儿童青少年占比
     * @param
     * @return
     * @throws Exception
     */
    @ApiOperation("已近视儿童青少年占比2")
    @GetMapping("/getSchoolLevelStat")
    public AjaxResult getSchoolLevelStat(String schoolId) throws Exception {
        return success(myopiaService.getSchoolLevelStat(SecurityUtils.getAuthInfo().getOrganizeId()));
    }

    /**
     * 区域已近视儿童青少年占比
     * @param
     * @return
     * @throws Exception
     */
    @ApiOperation("区域已近视儿童青少年占比2")
    @GetMapping("/getLevelStat")
    public AjaxResult getLevelStat() throws Exception {
        return success(myopiaService.getLevelStat());
    }

    /**
     * 已近视儿童青少年占比列表
     * @param
     * @return
     * @throws Exception
     */
    @ApiOperation("已近视儿童青少年占比3")
    @GetMapping("/getClassProportion")
    public TableDataInfo getClassProportion(Integer pageNum,Integer pageSize) throws Exception {
        return getDataTable(myopiaService.getClassProportion(SecurityUtils.getAuthInfo().getOrganizeId(),pageNum,pageSize));
    }

    /**
     * 区域已近视儿童青少年占比3
     * @param
     * @return
     * @throws Exception
     */
    @ApiOperation("区域已近视儿童青少年占比3 type 1为年级单位 2为学校单位")
    @GetMapping("/getAreaProportion")
    public TableDataInfo getAreaProportion(Integer type,Integer pageNum,Integer pageSize) throws Exception {
        return getDataTable(myopiaService.getAreaProportion(type,pageNum,pageSize));
    }

    /**
     * 年级高危统计
     * @param
     * @return
     * @throws Exception
     */
    @ApiOperation("年级高危统计")
    @GetMapping("/getRiskProportion")
    public AjaxResult getRiskProportion(String schoolId) throws Exception {
        List<MyopiaRiskVO> vos = myopiaService.getRiskProportion(SecurityUtils.getAuthInfo().getOrganizeId());
        return success(vos);
    }

    /**
     * 区域高危统计
     * @param
     * @return
     * @throws Exception
     */
    @ApiOperation("区域高危统计 type 1为年级单位 2为学校单位")
    @GetMapping("/getAreaRiskProportion")
    public AjaxResult getAreaRiskProportion(Integer type) throws Exception {
        List<MyopiaRiskVO> vos = myopiaService.getAreaRiskProportion(type);
        return success(vos);
    }

    /**
     * 视力档案区域
     * @param
     * @return
     * @throws Exception
     */
    @ApiOperation("视力档案区域")
    @GetMapping("/getSchoolCount")
    public TableDataInfo getSchoolCount(MyopiaAreaListDTO dto) throws Exception {
        return getDataTable(myopiaService.getSchoolCount(dto));
    }

    /**
     * 上传学校普查表
     * @param dto
     * @return
     * @throws Exception
     */
    @ApiOperation("上传学校普查表")
    @PostMapping("/import")
    public ResponseEntity uploadFile(@Validated MyopiaInportDto dto) throws Exception {
        return myopiaService.importFile(dto);
    }

    /**
     * 下载普查表模板
     * @return
     * @throws Exception
     */
    @ApiOperation("下载普查表模板")
    @PostMapping("/getTemplate")
    public ResponseEntity getTemplate() throws Exception {
        return myopiaService.getTemplate();
    }


    /**
     * 下载高危表模板
     * @return
     * @throws Exception
     */
    @ApiOperation("下载高危表模板")
    @PostMapping("/getRiskTemplate")
    public ResponseEntity getRiskTemplate() throws Exception {
        return myopiaService.getRiskTemplate();
    }

    /**
     * 上传高危表
     * @param dto
     * @return
     * @throws Exception
     */
    @ApiOperation("上传高危表")
    @PostMapping("/importRisk")
    public ResponseEntity uploadRiskFile(@Validated MyopiaInportDto dto) throws Exception {
        return myopiaService.importRiskFile(dto);
    }

    /**
     * 区域上传学校普查表
     * @param
     * @return
     * @throws Exception
     */
    @ApiOperation("区域上传学校普查表")
    @PostMapping("/importArea")
    public ResponseEntity uploadAreaFile(MultipartFile file) throws Exception {
        return myopiaService.importAreaFile(file);
    }

    /**
     * 区域上传高危表
     * @param
     * @return
     * @throws Exception
     */
    @ApiOperation("区域上传高危表")
    @PostMapping("/importAreaRisk")
    public ResponseEntity uploadAreaRiskFile(MultipartFile file) throws Exception {
        return myopiaService.importAreaRiskFile(file);
    }

    /**
     * 批量删除近视管理档案
     */
    @ApiOperation("批量删除近视管理档案")
    @DeleteMapping("/{ids}")
    public AjaxResult batchDel(@PathVariable Long[] ids) {
        myopiaService.batchDel(ids);
        return success();
    }

}
